/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FOUNDATION_DISCOVERY_CLIENT_H
#define FOUNDATION_DISCOVERY_CLIENT_H

#include "utils_noncopyable.h"
#include <memory>
#include <string>
#include <functional>
#include <nlohmann/json.hpp>

namespace El {
namespace Discovery {

class IDiscoveryClient {
public:
    using Proc = std::function<void(const nlohmann::json &)>;

    static IDiscoveryClient &GetInstance();

    virtual ~IDiscoveryClient() = default;

    /**
     * 启动发现服务客户端
     * @param timeout 发现超时时间(秒)，超时后自动停止服务
     * @return 成功返回true，失败返回false
     */
    virtual bool Start(int32_t timeout = 5) = 0;

    /**
     * 停止发现服务客户端
     */
    virtual void Stop() = 0;

    /**
     * 注册回调函数，用于接收发现结果
     * @param proc 回调函数
     * @return 注册句柄，用于后续取消注册，失败返回-1
     */
    virtual int32_t Register(const Proc &proc) = 0;

    /**
     * 取消注册回调函数
     * @param handle 注册时返回的句柄
     */
    virtual void Unregister(int32_t handle) = 0;
};

} // namespace Discovery
} // namespace El

#endif // FOUNDATION_DISCOVERY_CLIENT_H
